# coding=utf8
__author__ = 'lijian'

import baseFrame
import ConcentServer
import threading
import time
import datetime
from utils import byteUtil
from utils import bcdUtil
import config

from protocol.uplink.packet import *
from protocol.uplink import frameFactory


def encodeStr(str, size):
    data = list(struct.unpack('B' * len(str), str))
    data.extend([0] * (size - len(str)))
    return data


class MainWindow(baseFrame.MyFrame):
    def __init__(self):
        super(MainWindow, self).__init__(None)

    def startServer(self, event):
        config.readConfig()

        self.refreshTh = threading.Thread(target=ConcentServer.startServer)
        self.refreshTh.setDaemon(True)
        self.refreshTh.start()

    def on_click_04_01(self, event):
        data = []
        slaveTimeout = 120  # 确认超时时间
        bs = byteUtil.encodeShort(slaveTimeout)
        bs[1] = bs[1] & 0xf
        retry = 5  # 重试次数
        bs[1] = retry << 4 | bs[1]
        data.extend(bs)

        realtime = 0  # 实时数据自动上报
        history = 0 << 1  # 历史数据自动上报
        event = 1 << 2  # 事件数据自动上报
        data.append(realtime | history | event)

        heartbeatCycle = 3  # 心跳周期
        data.append(heartbeatCycle)

        dataUnit = DataUnit(pn=0, fn=1, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 主站IP地址和端口
    def on_click_04_02(self, event):
        data = [127, 0, 0, 1]
        data.extend(byteUtil.encodeShort(8483))
        apnStr = "3gnet"
        apn = list(struct.unpack('B' * len(apnStr), apnStr))
        apn.extend([0] * (16 - len(apn)))
        data.extend(apn)
        dataUnit = DataUnit(pn=0, fn=2, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_04_03(self, event):
        data = []
        data.extend([0xff, 0xf, 0, 0x1, 0x2, 0x3, 0x4, 0xf])
        data.extend([0xff, 0xf, 0, 0x1, 0x2, 0x3, 0x4, 0xf])
        data.extend([0xff, 0xf, 0, 0x1, 0x2, 0x3, 0x4, 0xf])
        dataUnit = DataUnit(pn=0, fn=3, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 设备基本信息
    def on_click_04_04(self, event):
        data = []
        data.extend(bcdUtil.numberToBcd(9080, 6))  # 控制箱编号
        data.extend(bcdUtil.numberToBcd(2088, 8))  # 终端地址
        data.extend(bcdUtil.numberToBcd(8888888888, 5))  # 经度
        data.extend(bcdUtil.numberToBcd(9999999999, 5))  # 纬度
        data.append(1)  # 是否启用单灯
        data.extend(byteUtil.encodeShort(100))  # 单灯通信频点

        dataUnit = DataUnit(pn=0, fn=4, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 终端事件检测配置参数
    def on_click_04_05(self, event):
        data = [12, 20, 30, 40, 50]
        dataUnit = DataUnit(pn=0, fn=5, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯事件检测配置参数
    def on_click_04_06(self, event):
        data = []
        data.append(20)  # (A)
        data.append(10)  # (A)
        data.append(70)  # (mA)
        data.append(60)  # (mA)
        data.extend(byteUtil.encodeA5(66.8))
        data.extend(byteUtil.encodeA5(66.8))
        data.append(50)  # (mA)
        data.append(40)  # (mA)
        data.append(30)  # (mA)
        data.append(20)  # (mA)

        dataUnit = DataUnit(pn=0, fn=6, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 控制器开关灯时间参数
    def on_click_04_09(self, event):
        data = []
        now = datetime.datetime.now()
        data.append(1)  # 日
        data.append(1)  # 月
        data.extend(byteUtil.encodeShort(366))  # 天数

        onTime = datetime.datetime(now.year, 1, 1, 18, 0, 0)
        offTime = datetime.datetime(now.year, 1, 1, 6, 0, 0)

        c = 0
        for i in range(366):
            data.extend(bcdUtil.numberToBcd(onTime.minute))
            data.extend(bcdUtil.numberToBcd(onTime.hour))
            data.extend(bcdUtil.numberToBcd(offTime.minute))
            data.extend(bcdUtil.numberToBcd(offTime.hour))

            c += 1
            if c == 10:
                onTime = onTime + datetime.timedelta(minutes=1)
                offTime = offTime + datetime.timedelta(minutes=1)
                c = 0

        dataUnit = DataUnit(pn=0, fn=9, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 信息量检测间隔时间
    def on_click_04_f11(self, event):
        data = []
        data.extend(bcdUtil.numberToBcd(1000, 2))  # DI量检测间隔
        data.extend(bcdUtil.numberToBcd(5000, 3))  # AI量检测间隔
        data.extend(bcdUtil.numberToBcd(2000, 2))  # 智能表抄表间隔

        dataUnit = DataUnit(pn=0, fn=11, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 控制回路参数
    def on_click_04_12(self, event):
        data = []
        data.extend([0x0f, 0xf0])
        data.append(1)
        data.append(3)
        dataUnit = DataUnit(pn=0, fn=12, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 控制器、单灯分组自动控制参数
    def on_click_04_13(self, event):
        data = []
        data.append(1)  # 启用标志
        data.append(2)  # 本次设ra置的控制组数

        data.append(1)  # 配置编号
        data.append(1)  # 操作方式
        data.append(0)  # 控制类型
        data.append(255)  # 目标状态
        data.append(0)  # 操作相对时间值
        data.extend([0x30, 0x45, 0x20, 0x15, 0x8, 0x14])  # 操作绝对时间值

        data.append(2)  # 配置编号
        data.append(0)  # 操作方式
        data.append(1)  # 控制类型
        data.append(00)  # 目标状态
        data.append(200)  # 操作相对时间值
        data.extend([0, 0, 0, 0, 0, 0])  # 操作绝对时间值

        dataUnit = DataUnit(pn=1, fn=13, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 集中器与单灯控制器关系参数设置
    def on_click_04_17(self, event):
        data = [10]  # 本次下发单灯控制器个数
        for i in range(1, 11):
            term = []
            term.extend(byteUtil.encodeShort(i))  # 设备序号
            term.append(1)  # 有效标志
            term.extend(byteUtil.encodeLong(2340+i))  # 地址
            term.append(1)  # 回路有效标志
            term.extend(byteUtil.encodeInt(i))  # 所处杆号
            data.extend(term)
        dataUnit = DataUnit(pn=0, fn=17, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯控制器与灯具关系参数
    def on_click_04_18(self, event):
        units = []

        lampNo = 1
        for k in range(10):
            data = [1]  # 本次下发单灯控制器灯具参数个数
            data.extend(byteUtil.encodeShort(lampNo))  # 灯具序号
            data.append(1)  # 启用标志
            data.append(1)  # 出线系号
            data.append(1)  # 相别
            data.append(1)  # 回路号

            dataUnit = DataUnit(pn=k + 1, fn=18, data=data)
            units.append(dataUnit)

            lampNo += 1

        frame = frameFactory.buildInitiativeFrame(4, units)
        ConcentServer.sendToAllClient(frame)

    # 单灯自动控制参数
    def onClick_04_19(self, event):
        data = []
        data.append(1)  # 启用标志
        data.append(2)  # 本次设ra置的控制组数

        data.append(1)  # 配置编号
        data.append(1)  # 操作方式
        data.append(0)  # 控制类型
        data.append(255)  # 目标状态
        data.append(0)  # 操作相对时间值
        data.extend([0x30, 0x45, 0x20, 0x15, 0x8, 0x14])  # 操作绝对时间值

        data.append(2)  # 配置编号
        data.append(0)  # 操作方式
        data.append(1)  # 控制类型
        data.append(00)  # 目标状态
        data.append(200)  # 操作相对时间值
        data.extend([0, 0, 0, 0, 0, 0])  # 操作绝对时间值

        dataUnit = DataUnit(pn=1, fn=19, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯分组参数
    def on_click_04_20(self, event):
        units = []

        for i in range(10):
            data = []
            data.append(2)  # 本次设定的分组个数
            data.append(1)
            data.append(3)

            dataUnit = DataUnit(pn=i + 1, fn=20, data=data)
            units.append(dataUnit)

        frame = frameFactory.buildInitiativeFrame(4, units)
        ConcentServer.sendToAllClient(frame)

    # 遥信量分类参数
    def on_click_04_25(self, event):
        data = []
        data.append(20)  # 本次配置的遥信点个数
        data.append(0)  # 起始遥信点号

        for i in range(data[0]):
            type = i % 3
            line = i % 4
            phase = i % 5
            data.append(type)
            data.append(line)
            data.append(phase)

        dataUnit = DataUnit(pn=1, fn=25, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_04_26(self, event):
        data = []
        data.append(20)  # 本次配置的遥信点个数
        data.append(1)  # 起始遥信点号

        for i in range(data[0]):
            data.append(1)
            data.append(i % 8)
            data.append(i)
            data.append(i % 3)

            data.extend([5, 8])
            data.extend([2, 4])
            data.extend([1, 3])
            data.extend([0, 2])

        dataUnit = DataUnit(pn=1, fn=26, data=data)
        frame = frameFactory.buildInitiativeFrame(4, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # rtu遥控
    def on_click_05_01(self, event):
        dataUnit = DataUnit(pn=0, fn=1, data=[0, 255])
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯点控
    def onClick_05_02(self, event):
        state = self.m_rs.GetSelection()
        if state==0:
            level=255
        else:
            level=0

        dataUnit = DataUnit(pn=1, fn=2, data=[state, level])
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯组控
    def onClick_05_03(self, event):
        dataUnit = DataUnit(pn=1, fn=3, data=[1, 0])
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯控制器轮询状态切换
    def onClick_05_09(self, event):
        dataUnit = DataUnit(pn=0, fn=9, data=[0, 1])
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯控制器复位
    def onClick_05_10(self, event):
        dataUnit = DataUnit(pn=1, fn=10, data=[1])
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯控制器组复位
    def onClick_05_11(self, event):
        dataUnit = DataUnit(pn=3, fn=11, data=[1])
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 新增单灯预约控制
    def onClick_05_12(self, event):

        # units = []
        # for i in range(1, 10):
        #     data = []
        #     data.append(i)  # No
        #     now = datetime.datetime(2014, 12, 10, 18, 30, 0)
        #     bcd = bcdUtil.hexTobcd([now.second, now.minute, now.hour, now.day, now.month, now.year - 2000])
        #     data.extend(bcd)
        #     data.append(1)
        #     data.append(255)
        #
        #     dataUnit = DataUnit(pn=i, fn=12, data=data)
        #     units.append(dataUnit)

        data = []
        data.append(1)  # No
        now = datetime.datetime(2015, 05, 18, 18, 35, 0)
        bcd = bcdUtil.hexTobcd([now.second, now.minute, now.hour, now.day, now.month, now.year - 2000])
        data.extend(bcd)
        data.append(1)
        data.append(0)

        dataUnit = DataUnit(pn=1, fn=12, data=data)
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)


    # 新增单灯组预约控制
    def onClick_05_13(self, event):
        units = []
        for i in range(1, 3):
            data = []
            data.append(i)  # No
            now = datetime.datetime(2014, 12, 10, 19, 30, 0)
            bcd = bcdUtil.hexTobcd([now.second, now.minute, now.hour, now.day, now.month, now.year - 2000])
            data.extend(bcd)
            data.append(1)
            data.append(255 - i)

            dataUnit = DataUnit(pn=i, fn=13, data=data)
            units.append(dataUnit)

        frame = frameFactory.buildInitiativeFrame(5, units)
        ConcentServer.sendToAllClient(frame)

    # 删除单灯预约控制
    def onClick_05_14(self, event):
        data = [2]
        dataUnit = DataUnit(pn=1, fn=14, data=data)
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 删除单灯组预约控制
    def onClick_05_15(self, event):
        data = [0xff]
        dataUnit = DataUnit(pn=1, fn=15, data=data)
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 校时
    def onClick_05_31(self, event):
        now = datetime.datetime.now()
        bcd = bcdUtil.hexTobcd([now.second, now.minute, now.hour, now.day, now.month, now.year - 2000])
        data = bcd
        dataUnit = DataUnit(pn=0, fn=31, data=data)
        frame = frameFactory.buildInitiativeFrame(5, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 终端上行通信口通信参数设置
    def on_click_0A_01(self, event):
        dataUnit = DataUnit(pn=0, fn=1, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0A_02(self, event):
        dataUnit = DataUnit(pn=0, fn=2, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0A_03(self, event):
        dataUnit = DataUnit(pn=0, fn=3, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 设备基本信息
    def on_click_0A_04(self, event):
        dataUnit = DataUnit(pn=0, fn=4, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 终端事件检测配置参数
    def on_click_0A_05(self, event):
        dataUnit = DataUnit(pn=0, fn=5, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯事件检测配置参数
    def on_click_0A_06(self, event):
        dataUnit = DataUnit(pn=0, fn=6, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 控制器开关灯时间参数
    def on_click_0A_09(self, event):
        data = []
        data.append(1)
        data.append(1)
        data.extend(byteUtil.encodeShort(366))
        dataUnit = DataUnit(pn=0, fn=9, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

        #

    # 信息量检测间隔时间(F11)
    def on_click_0A_f11(self, event):
        dataUnit = DataUnit(pn=0, fn=11, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 控制回路参数
    def on_click_0A_12(self, event):
        dataUnit = DataUnit(pn=0, fn=12, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 控制器、单灯分组自动控制参数
    def on_click_0A_13(self, event):
        dataUnit = DataUnit(pn=1, fn=13, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 集中器与单灯控制器关系参数设置查询
    def on_click_0A_17(self, event):
        data = []
        data.append(3)  # 个数
        for i in range(1, 4):
            data.extend(byteUtil.encodeShort(i))

        dataUnit = DataUnit(pn=0, fn=17, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯控制器与灯具关系参数
    def on_click_0A_18(self, event):
        data = []
        data.append(1)  # 个数
        data.extend(byteUtil.encodeShort(1))

        dataUnit = DataUnit(pn=1, fn=18, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯控制器与灯具关系参数查询
    def onClick_0A_18(self, event):
        data = []
        data.append(4)
        for i in range(1, 5):
            data.extend(byteUtil.encodeShort(i))

        dataUnit = DataUnit(pn=0, fn=18, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯自动控制参数查询
    def onClick_0A_19(self, event):
        dataUnit = DataUnit(pn=1, fn=19, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0A_20(self, event):
        dataUnit = DataUnit(pn=1, fn=20, data=[])
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)


    def on_click_0A_25(self, event):
        data = []
        data.append(2)
        data.append(2)
        dataUnit = DataUnit(pn=1, fn=25, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0A_26(self, event):
        data = []
        data.append(2)
        data.append(2)
        dataUnit = DataUnit(pn=1, fn=26, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0A, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 终端日历时钟
    def on_click_0C_02(self, event):
        dataUnit = DataUnit(pn=0, fn=2, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 节能开关档位
    def on_click_0C_03(self, event):
        dataUnit = DataUnit(pn=0, fn=3, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 单灯轮询查询
    def on_click_0C_04(self, event):
        dataUnit = DataUnit(pn=0, fn=4, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 模拟量查询
    def on_click_0C_09(self, event):
        dataUnit = DataUnit(pn=2, fn=9, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    #状态量查询
    def on_click_0C_10(self, event):
        dataUnit = DataUnit(pn=2, fn=10, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    # 模拟量批量查询
    def on_click_0C_11(self, event):
        data = [10, 0]
        dataUnit = DataUnit(pn=2, fn=11, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    #状态量批量查询
    def on_click_0C_12(self, event):
        data = [10, 0]
        dataUnit = DataUnit(pn=2, fn=12, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0C_33(self, event):
        dataUnit = DataUnit(pn=1, fn=33, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0C_34(self, event):
        for i in range(1, 10):
            dataUnit = DataUnit(pn=i, fn=34, data=None)
            frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
            ConcentServer.sendToAllClient(frame)

            time.sleep(1)

    def on_click_0C_35(self, event):
        dataUnit = DataUnit(pn=1, fn=35, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)


    def on_click_0C_36(self, event):
        dataUnit = DataUnit(pn=1, fn=36, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)


    def on_click_0C_37(self, event):
        dataUnit = DataUnit(pn=1, fn=37, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_0C_38(self, event):
        dataUnit = DataUnit(pn=1, fn=38, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)


    def on_click_0C_39(self, event):
        dataUnit = DataUnit(pn=1, fn=39, data=None)
        frame = frameFactory.buildInitiativeFrame(0x0C, dataUnit)
        ConcentServer.sendToAllClient(frame)


    def on_click_lamp_detail(self, event):
        dataUnits = []
        dataUnits.append(DataUnit(pn=1, fn=33, data=None))
        dataUnits.append(DataUnit(pn=1, fn=34, data=None))
        dataUnits.append(DataUnit(pn=1, fn=35, data=None))
        dataUnits.append(DataUnit(pn=1, fn=36, data=None))
        dataUnits.append(DataUnit(pn=1, fn=37, data=None))
        dataUnits.append(DataUnit(pn=1, fn=38, data=None))
        dataUnits.append(DataUnit(pn=1, fn=39, data=None))
        # dataUnits.append(DataUnit(pn=1, fn=35, data=None))

        frame = frameFactory.buildInitiativeFrame(0x0c, dataUnits)
        ConcentServer.sendToAllClient(frame)

    def onClick_0D_17(self, event):
        data = [0x30, 0x14, 0x11, 0x12, 0x14]
        data.append(1)
        data.append(50)
        dataUnit = DataUnit(pn=1, fn=17, data=data)
        frame = frameFactory.buildInitiativeFrame(0x0D, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def onClick_0D_18(self, event):
        super(MainWindow, self).onClick_0D_18(event)

    def onClick_0D_19(self, event):
        super(MainWindow, self).onClick_0D_19(event)

    def onClick_0D_20(self, event):
        pass

    def on_click_10_09(self, event):
        data = []
        data.extend([192, 168, 1, 25])
        data.extend(byteUtil.encodeShort(21))

        data.extend([192, 168, 1, 25])
        data.extend(byteUtil.encodeShort(21))

        data.extend(encodeStr("lijian", 10))
        data.extend(encodeStr("123456", 10))

        data.extend(encodeStr("/home/lijian/ftp", 20))
        data.extend(encodeStr("/home/lijian/ftp", 20))

        data.extend(encodeStr("py.tar.gz", 10))
        data.extend(encodeStr("py.tar.gz", 10))
        data.extend(encodeStr("py.tar.gz", 10))
        data.extend(encodeStr("py.tar.gz", 10))
        data.extend(encodeStr("py.tar.gz", 10))

        dataUnit = DataUnit(pn=0, fn=9, data=data)
        frame = frameFactory.buildInitiativeFrame(0x10, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_10_10(self, event):
        dataUnit = DataUnit(pn=0, fn=10, data=[])
        frame = frameFactory.buildInitiativeFrame(0x10, dataUnit)
        ConcentServer.sendToAllClient(frame)

    def on_click_test_1(self, event):
        raw = [0x68, 0x1C, 0x00, 0x1C, 0x00, 0x68, 0x75, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xE1, 0x00,
               0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x01, 0x01, 0x24, 0x04, 0x11, 0x17, 0x00,
               0xDD, 0xFF, 0x16]

        # import decode

        from protocol.uplink.decode import *

        address = raw[6:14]
        decoder = decode.DataRegionDecode(raw[14:-3])
        dataRegion = decoder.decodeDataRegion()

        frame = Frame(dataRegion, address)
        ConcentServer.sendToAllClient(frame)

    def on_click_send(self, event):
        txt = self.m_input.GetValue()
        array = txt.split(" ")
        raw = []
        for c in array:
            raw.append(int(c, 16))

        ConcentServer.sendToAllClient(raw)
















